<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set>  
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>商品列表</title>


    <link rel="shortcut icon" href="${ctx}/favicon.ico"> <link href="${ctx}/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctx}/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctx}/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctx}/css/animate.css" rel="stylesheet">
    <link href="${ctx}/css/style.css?v=4.1.0" rel="stylesheet">
</head>

<body>
        <div class="col-sm-12">
                <!-- Example Rowstyle -->
                <div class="example-wrap margin-sm-0">
                    <h4 class="example-title">商品列表</h4>
                    <div class="example">
                        <table data-toggle="table" data-mobile-responsive="true" data-row-style="rowStyle" data-height="500">
                            <thead>
                                <tr>
                                        <th data-field="goods_id" data-checkbox="true"></th>
                                        <th data-field="id">商品编号</th>
                                        <th data-field="name">商品名称</th>
                                        <th data-field="classification">商品分类</th>
                                        <th data-field="price">单价</th>
                                        <th data-field="unit">规格</th>
                                        <th data-field="origin">产地</th>
                                        <th data-field="introduce">介绍</th>
                                        <th data-field="remark">备注</th>
                                </tr>
                            </thead>
                            <c:forEach var="goodslist" items="${goodslist}">
                            	<tr>
                            		<td class="goodsId"></td>
                            		<td>${goodslist.goods_id}</td>
                            		<td>${goodslist.goods_name}</td>
                            		<td>${goodslist.goods_classification}</td>
                            		<td>${goodslist.price}</td>
                            		<td>${goodslist.unit}</td>
                            		<td>${goodslist.origin}</td>
                            		<td>${goodslist.introduce}</td>
                            		<td>${goodslist.remark}</td>
                            	</tr>
                            
                            </c:forEach>
                        </table>
                        <div class="btn-group hidden-xs" id="exampleTableEventsToolbar" role="group" style=" margin-top:15px;">
                                <button type="button" class="btn btn-outline btn-default" onclick="addgoods()">
                                    <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
                                </button>
                                <button type="button" class="btn btn-outline btn-default" onclick="editgoods()">
                                    <i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
                                </button>
                                <button type="button" class="btn btn-outline btn-default" onclick="deletegoods()">
                                    <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                                </button>
                                <button type="button" class="btn btn-outline btn-default" onclick="showlist()">
                                    <i class=" glyphicon glyphicon-refresh" aria-hidden="true"></i>
                                </button>
                        </div>
                        <div id="pagination"></div>
                    </div>
                </div>
                <!-- End Example Rowstyle -->
            </div>
</body>




    <!-- 全局js -->
    <script src="${ctx}/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctx}/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="${ctx}/dist/jquery-bootstrap-pagination/jquery-bootstrap-pagination.js"></script>
    
    
    <script type="text/javascript" src="${ctx}/dist/layer-v3.1.1/layer/layer.js"></script>

    <!-- 自定义js -->
    <script src="${ctx}/js/content.js?v=1.0.0"></script>


    <!-- Bootstrap table -->
    <script src="${ctx}/dist/onlyone/bootstrap-table.min.js"></script>
    <script src="${ctx}/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script src="${ctx}/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

    <!-- Peity -->
    <script src="${ctx}/js/demo/bootstrap-table-demo.js"></script>
   
    
    <script>
    	//分页
/*             $("#pagination").pagination({
               total_pages: 10,
              current_page: 2,
              prev: "上一页",
              next: "下一页",
              callback: function(event, page) {
                  return alert("Page " + page + " was clicked!");
            }
          });  
             */
         //显示商品列表信息
         function showlist(){
        	 window.location.href="${ctx}/GoodsServlet/listAll";
         }
            
         //添加商品
         function addgoods(){
        	 parent.layer.open({
        		 type:2,
        		 content:['${ctx}/page/user/goodsManage/addGoods.jsp','no'],
        		 area:['30%','50%'],
 	 			 //offset:['10%','20%']
        	 });
         }
         
         //删除商品
         function deletegoods(){
        	 if( $('tr.selected').size()==0){
        		 parent.layer.msg("至少选择一个");
        		 return;
        	 }
        	 if(confirm('确定要删除所选吗？')){
        		$('tr.selected').each(function(){
        			
        			
        			var goods_id=$(this).children('td').eq(1).html();
        			$.get('${ctx}/GoodsServlet/deleteById',{"goods_id":goods_id},function(data){
        				if(data){
        					parent.layer.msg("删除成功");
        					showlist();
        				}else{
        					parent.layer.mag("删除失败");
        				}
        			});
        			//window.location.href="${ctx}/GoodsServlet/deleteById?goods_id="+goods_id;
        			//alert($(this).children('td').eq(1).html());
        		});
        	 }
        	
         }
         
         //修改商品
         function editgoods(){
        	 if( $('tr.selected').size()!=1){
        		 parent.layer.msg("请选择一个要修改的商品");
        		 return;
        	 }else{
 
        	$('tr.selected').each(function(){
        		 
        			var goods_id=$(this).children('td').eq(1).html();
        			parent.layer.open({
               		 type:2,
               		 content:['${ctx}/GoodsServlet/preEditGoods?goods_id='+goods_id,'no'],
               		 area:['30%','50%'],
        	 		 //offset:['10%','20%']
               	 	});
        		
        			
        	});
        	 }
        	 
        	
         }
    </script>
</html>